<template>
  <div class="home">
    <!-- <img alt="Vue logo" src="../assets/logo.png"> -->
    <!-- <HelloWorld msg="Welcome to Your Vue.js App"/> -->
    <button @click="gopay">点击支付</button>
  </div>
</template>

<script>
import axios from 'axios';
import qs from 'qs';
// @ is an alias to /src
//import HelloWorld from '@/components/HelloWorld.vue'
export default {
  name: 'HomeView',
  // components: {
  //   HelloWorld
  // },
  methods:{
    gopay(){
      // axios.post('http://127.0.0.1:3000/api/payment').then((res)=>{
      //   console.log(res);
      // }).catch((err)=>{
      //   console.log(err);
      // })
      let data = {
        orderId:'sdfg1234'
      };
      axios({
        url:'http://127.0.0.1:3000/api/payment',
        method:'post',
        headers:{
          'content-type':'application/x-www-form-urlencoded'
        },
        data:qs.stringify(data)
      }).then((res)=>{
        if(res.data.success){
          window.location.href = res.data.paymentUrl;
        }
        console.log(res);
      }).catch((err)=>{
        console.log(err);
      })
    }
  }
}
</script>
